<template>
  <div class="nav-footer">
    <!-- 底部导航 -->
    <div class="nav-footer">
      <div class="nav-footer-item" @click="jumpTo('home')" :class="$route.name === 'home' ? 'active':''"><span class="iconfont icon-home"></span><span>首页</span></div>
      <div class="nav-footer-item" @click="jumpTo('member')" :class="$route.name === 'member' ? 'active':''"><span class="iconfont icon-weibiaoti2fuzhi12"></span><span>会员</span></div>
      <div class="nav-footer-item" @click="jumpTo('home')"><span class="iconfont icon-gouwuche"></span><span>购物车</span>
      <span class='badge'>{{$store.state.cart.goodsNum}}</span>
      </div>
      <div class="nav-footer-item" @click="jumpTo('home')"><span class="iconfont icon-xiazai17"></span><span>搜索</span></div>
    </div>
  </div>
</template>
<script>
export default {
  methods: {
    jumpTo (pathName) {
      this.$router.push({name: pathName})
      // console.log(this.$route.name)
    }
  },
  // 页面一加载就获取到本地数据,确保渲染的是最新数据
  created () {
    // this.cartListPage = JSON.parse(localStorage.getItem('cartList') || '[]')

    // 触发mutations里面的setNum
    this.$store.commit('setNum')
  },
  computed: {
    // totalNum () {
    //   let total = 0
    //   // 循环页面数组，将所有项的num加起来
    //   this.cartListPage.map(item => {
    //     total += item.num
    //   })
    //   return total
    // }
  }
}
</script>

<style lang="scss" scoped>
  .nav-footer {
    font-size: 16px;
    display: flex;
    position: fixed;
    bottom: 0;
    height: 50px;
    width: 100%;
    border-top: 1px solid #e7e7e7;
    background-color: #fff;
    .nav-footer-item {
      position: relative;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      width: 25%;
      .badge {
        position: absolute;
        top: 3%;
        left: 50%;
        width: 14px;
        height: 14px;
        border-radius: 7px;
        background-color: #e4393c;
        text-align: center;
        line-height: 14px;
        color: white;
        font-size: 12px;
      }
    }
  }
  .active {
    color: #26a2ff;
  }
</style>
